package com.bobo.demo.Thread;


//多个线程同时操作同一个对象
//买火车票的例子
public class TestRunnable2 implements Runnable {
    //票数
    private int tickNums = 10;

    @Override
    public void run() {

        while(true) {
            if (tickNums <= 0) {
                break;
            }
            //模拟延时
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"-->拿到了第"+tickNums--+"-票");
        }

    }

    public static void main(String[] args) {
        TestRunnable2 t1 = new TestRunnable2();
        //创建线程对象，通过线程对象来开启我们的现场，代理

        new Thread(t1,"苏苏").start();
        new Thread(t1,"波波").start();
        new Thread(t1,"黄牛党").start();

    }
}
